package com.cnhis.cloudhealth.clinical.hosnurse.hosoffice.bo;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.hosnurse.hosoffice.dao.HosOfficeDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

@Service
public class HosOfficeBo {
  @Resource
  private HosOfficeDao hosOfficeDao;
  @Resource
  private GetNewId getNewId;
  public ModelVo getOfficeName(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
			   list=hosOfficeDao.getOfficeName(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo checkOfficeOperationOption(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
			   list=hosOfficeDao.checkOfficeOperationOption(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo defaultCurrentOffice(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.defaultCurrentOffice(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo getCurrentOffice(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
			List list =null;
			try {
			   list=hosOfficeDao.getCurrentOffice(map);
			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(list);
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(list);
			return mo;
  }
  private String getBDN01(Map map)throws Exception{
	  return hosOfficeDao.getBDN01(map);
  }
  @SuppressWarnings("unchecked")
public ModelVo defaultMedical(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
			if("0".equals(map.get("aParamno").toString())){
				map.put("BDN01", getBDN01(map));
				list = hosOfficeDao.defaultMedical0(map);
			}
			if("1".equals(map.get("aParamno").toString())){
				list = hosOfficeDao.defaultMedical1(map);
			}
		   list=hosOfficeDao.getCurrentOffice(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo chenckGynecology(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.chenckGynecology(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo queryBedSpace(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
			List list =null;
			try {
			   list=hosOfficeDao.queryBedSpace(map);
			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(list);
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(list);
			return mo;
  }
  public ModelVo queryOfficeList(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryOfficeList( map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo queryBedLevel()throws Exception{
	  String adate = DateUtils.getDateStr(new Date())+" 23:59:59.999";
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
			Map map = new HashMap();
			map.put("adate", adate);
		   list=hosOfficeDao.queryBedLevel(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo queryArea(long BCK01B)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryArea(BCK01B);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo queryProofeadAdviceOffice(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryProofeadAdviceOffice(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	  
  }
  public ModelVo queryPatientBedLevel(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryPatientBedLevel(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  
  public ModelVo patientOutDept(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
	  List list =null;
	  List list1 =null;
		try {
			/*list = hosOfficeDao.getroad(map);
			if(list!=null&&list.size()>0){
				mo.setResult(StaticKeys.OH_FALSE);
				mo.setResultMsg("此病人在临床路径中，不能办理转科");
				return mo;
			}*/
			list = hosOfficeDao.getNotStop(map);
			if(list!=null&&list.size()>0){
				mo.setResult(StaticKeys.OH_FALSE);
				mo.setResultMsg("此病人还有未停止医嘱，不能办理转科");
				return mo;
			}
			list = hosOfficeDao.getNotSend(map);
			if(list!=null&&list.size()>0){
				mo.setResult(StaticKeys.OH_FALSE);
				mo.setResultMsg("此病人还有未发送药品，不能办理转科");
				return mo;
			}
			list1 = hosOfficeDao.patientOutDept(map);
		   if(list1!=null&&list1.size()>0){
			   mo.setList(list1);
			   mo.setResult(StaticKeys.OH_SUCCESS);
			   mo.setRows(list1);
		   }else{
			   mo.setResult(StaticKeys.OH_FALSE);
			   mo.setResultMsg("此病人没有执行转科医嘱，不能办理转科");
		   }
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		return mo;
  }
  public ModelVo patientOutDept1(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		try {
			Long ct = hosOfficeDao.patientOutDept1(map);
		   if(ct==null||ct==0l){
			   mo.setResult(StaticKeys.OH_FALSE);
			   mo.setResultMsg("此病人没有执行转科医嘱，不能办理撤销转科");
		   }else{
			   mo.setResult(StaticKeys.OH_SUCCESS);
		   }
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		return mo;
  }
  public ModelVo queryAllOffice()throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryAllOffice();
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo queryAllWorkRoom()throws Exception{
	  
	  ModelVo mo = new ModelVo();
			List list =null;
			try {
			   list=hosOfficeDao.queryAllWorkRoom();
			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(list);
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(list);
			return mo;
	  
  }
  public ModelVo queryCareLevel()throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryCareLevel();
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	  
  }
  public ModelVo queryNewArea(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.queryNewArea(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo getNewArea(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
			List list =null;
			try {
			   list=hosOfficeDao.getNewArea(map);
			} catch (Exception e) {
				e.printStackTrace();
				mo.setResult(StaticKeys.OH_FALSE);
				return mo;
			}
			mo.setList(list);
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setRows(list);
			return mo;
  }
  public ModelVo getBedLevel()throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		Map hs = new HashMap();
		hs.put("aDate", DateUtils.getDateStr(new Date())+" 23:59:59");
		try {
		   list=hosOfficeDao.getBedLevel(hs);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }
  public ModelVo getNewOffice(Map map)throws Exception{
	  ModelVo mo = new ModelVo();
		List list =null;
		try {
		   list=hosOfficeDao.getNewOffice(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
  }

	public ModelVo queryNullBed(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		try {
			list=hosOfficeDao.queryNullBed(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	public ModelVo queryBed(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		try {
			list=hosOfficeDao.queryBed(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	public ModelVo upbcq04a(Map map)throws Exception{
        ModelVo mo = new ModelVo();
        hosOfficeDao.upbcq04a(map);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setResultMsg("更换病人床位成功!");
        return mo;
    }
	public ModelVo queryBck01c(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		try {
			list=hosOfficeDao.queryBck01c(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	public ModelVo upbck01c(Map map)throws Exception{
        ModelVo mo = new ModelVo();
        map.put("lDate", DateUtils.getDateString(new Date()));
        map.put("aDate", DateUtils.getDateString(new Date()));
        map.put("lID", getNewId.nextId());
        hosOfficeDao.upbck01c(map);
        
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setResultMsg("更换病人病区成功!");
        return mo;
    }
	public ModelVo queryBck01d(Map map)throws Exception{
		ModelVo mo = new ModelVo();
		List list =null;
		try {
			list=hosOfficeDao.queryBck01d(map);
		} catch (Exception e) {
			e.printStackTrace();
			mo.setResult(StaticKeys.OH_FALSE);
			return mo;
		}
		mo.setList(list);
		mo.setResult(StaticKeys.OH_SUCCESS);
		mo.setRows(list);
		return mo;
	}
	public ModelVo upbck01d(Map map)throws Exception{
        ModelVo mo = new ModelVo();
        map.put("lDate", DateUtils.getDateString(new Date()));
        map.put("aDate", DateUtils.getDateString(new Date()));
        map.put("lID", getNewId.nextId());
        hosOfficeDao.upbck01d(map);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setResultMsg("更换病人科室成功!");
        return mo;
    }
}
